Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Agregando una alerta que dice "¡No encontrado!" si el cuadro de entrada en la barra de búsqueda no es nada

Estoy tratando de agregar una alerta que dice "no encontrado" cuando no buscas nada usando una barra de búsqueda que ya he programado en JavaScript. Algo como esto:

 if (document.getElementById('query').value = *variable for nothing*) { alert('Not found!') }

Este es un código de ejemplo. ¿Puede alguien darme una línea de código que haría esto pero es funcional?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¡Este es uno de los pocos casos en los que la solución es no escribir ningún código adicional !

Puede examinar la veracidad del .value de su elemento para ver si tiene un valor en él. Eso significa que verificaría la condición:

 if(document.getElementById('query').value) {

Si eso es verdad, entonces tiene un valor. Si es falso entonces no tiene valor.

 document.getElementById('test').addEventListener('click', () => { if (document.getElementById('query').value) { alert('It has a value'); } else { alert('It does not have a value'); } });
 <input id="query" type="text" /> <button id="test">Test</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!